using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Db4objects.Db4o;
using System.Data;
using MonitorTemperatura.Entidades;

namespace MonitorTemperatura.DataAccess
{
    public class ComunDAO
    {

        private IObjectContainer OpenFileRemote()
        {
            IObjectContainer db = Db4oFactory.OpenClient(Util.HOST, Util.PORT, Util.USER, Util.PASS);
            ConfigureDBObjects();
            return db;
        }

        private IObjectContainer OpenFile()
        {
            IObjectContainer db = Db4oFactory.OpenFile(Util.YapFileName);
            ConfigureDBObjects();
            return db;
        }

        private void CloseFile(IObjectContainer db)
        {
            db.Close();
        }

        public void DeleteAll()
        {
            IObjectContainer db = OpenFileRemote();
            Util.DeleteAll(db);
            CloseFile(db);
        }

        private void ConfigureDBObjects()
        {
            Db4oFactory.Configure().ObjectClass(typeof(Ubicacion)).CascadeOnUpdate(true);
            Db4oFactory.Configure().ObjectClass(typeof(Ubicacion)).CascadeOnDelete(true);
        }
    }
}
